<?php

namespace backend\modules\goods\controllers;

use backend\extensions\ApiBaseController;
use backend\services\goods\GoodsStockService;

class GoodsStockController extends ApiBaseController
{
    /**
     * 列表
     * * */
    public function actionList()
    {
        $params = \Yii::$app->request->get();
        $rules = [
            [['name', 'barcode', 'warehouse'], 'default', 'value' => 0, 'message' => '名称检索'],
            [['page'], 'default', 'value' => 1, 'message' => '页数'],
            [['page_size'], 'default', 'value' => 10000, 'message' => '每页显示总数'],
        ];
        $validate = $this->validateParams($params, $rules);
        if ($validate) {
            return $this->jsonError($validate);
        }
        $data = GoodsStockService::getList($this->params);
        return $this->jsonSuccess($data);
    }

    /**
     * 列表
     * * */
    public function actionLog()
    {
        $params = \Yii::$app->request->get();
        $rules = [
            [['name', 'barcode', 'warehouse', 'supply_id', 'buy_order_code'], 'default', 'value' => 0, 'message' => '名称检索'],
            [['page'], 'default', 'value' => 1, 'message' => '页数'],
            [['page_size'], 'default', 'value' => 10000, 'message' => '每页显示总数'],
        ];
        $validate = $this->validateParams($params, $rules);
        if ($validate) {
            return $this->jsonError($validate);
        }
        $data = GoodsStockService::getLog($this->params);
        return $this->jsonSuccess($data);
    }

    // 库存增加
    public function actionSave()
    {
        $params = \Yii::$app->request->post();
        $rules = [
            [['id', 'barcode', 'nums'], 'default', 'value' => 0, 'message' => '名称检索']
        ];
        $validate = $this->validateParams($params, $rules);
        if ($validate) {
            return $this->jsonError($validate);
        }
        $data = GoodsStockService::stockAdd($this->params);
        return $this->jsonSuccess($data);
    }




   
}
